home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / dns / ttl.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  1KB  |  46 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import dns.exception as dns
  5.  
  6. class BadTTL(dns.exception.SyntaxError):
  7.     pass
  8.  
  9.  
  10. def from_text(text):
  11.     if text.isdigit():
  12.         total = long(text)
  13.     elif not text[0].isdigit():
  14.         raise BadTTL
  15.     
  16.     total = 0x0L
  17.     current = 0x0L
  18.     for c in text:
  19.         if c.isdigit():
  20.             current *= 10
  21.             current += long(c)
  22.             continue
  23.         c = c.lower()
  24.         if c == 'w':
  25.             total += current * 0x93A80L
  26.         elif c == 'd':
  27.             total += current * 0x15180L
  28.         elif c == 'h':
  29.             total += current * 0xE10L
  30.         elif c == 'm':
  31.             total += current * 0x3CL
  32.         elif c == 's':
  33.             total += current
  34.         else:
  35.             raise BadTTL, "unknown unit '%s'" % c
  36.         current = 0
  37.     
  38.     if not current == 0:
  39.         raise BadTTL, 'trailing integer'
  40.     
  41.     if total < 0x0L or total > 0x7FFFFFFFL:
  42.         raise BadTTL, 'TTL should be between 0 and 2^31 - 1 (inclusive)'
  43.     
  44.     return total
  45.  
  46.